package org.rednebula.framework.core.log;



public abstract class Log {
	static ILogFactory logFactory = null;

	public static ClassLoader getClassLoader() {
		return Thread.currentThread().getContextClassLoader();
	}

	public static synchronized Log getLog(String name) {
		if (logFactory == null) {

			ClassLoader classLoader = getClassLoader();
			if (isLog4jAvailable(classLoader)) {
				logFactory = new Log4jLogFactory();

			} else if (classLoader.getResource("logging.properties") != null) {
				logFactory = new JdkLogFactory();
			} else {
				logFactory = new Log4jLogFactory();

			}
		}
		return logFactory.getLog(name);
	}
	public static synchronized Log getLog(Class name) {
		if (logFactory == null) {

			ClassLoader classLoader = getClassLoader();
			if (isLog4jAvailable(classLoader)) {
				logFactory = new Log4jLogFactory();

			} else if (classLoader.getResource("logging.properties") != null) {
				logFactory = new JdkLogFactory();
			} else {
				logFactory = new Log4jLogFactory();

			}
		}
		return logFactory.getLog(name);
	}
	static boolean isLog4jAvailable(ClassLoader classLoader) {
		try {
			Class.forName("org.apache.log4j.LogManager", false, classLoader);
			return true;
		} catch (ClassNotFoundException e) {
			return false;
		}
	}

	public abstract void error(String msg);

	public abstract void error(String msg, Throwable exception);

	public abstract boolean isInfoEnabled();

	public abstract void info(String msg);

	public abstract void info(String msg, Throwable exception);

	public abstract boolean isDebugEnabled();

	public abstract void debug(String msg);

	public abstract void debug(String msg, Throwable exception);

	public abstract boolean isTraceEnabled();

	public abstract void trace(String msg);

	public abstract void trace(String msg, Throwable exception);

	public abstract boolean isWarnEnabled();

	public abstract void warn(String msg);

	public abstract void warn(String msg, Throwable exception);
}
